package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tzbank.back.dao.AuthMapper;
import com.tzbank.back.service.AuthService;
import com.tzbank.entity.backstage.Auth;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

@Service
public class AuthServiceImpl implements AuthService {

	@Autowired
	private AuthMapper authMapper;

	@Transactional
	@Override
	public Map<String, Object> deleteAuth(Auth auth) throws Exception{
		this.authMapper.deleteAuth(auth);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> insertAuth(Auth auth) throws Exception{
		auth.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		auth.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.authMapper.insertAuth(auth);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> selectAuthByAutoId(int autoId) throws Exception{
		Auth auth = this.authMapper.selectAuthByAutoId(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), auth);
	}

	@Override
	public Map<String, Object> selectAuthList() throws Exception{
		List<Auth> auths = this.authMapper.selectAuthList();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), auths);
	}

	@Transactional
	@Override
	public Map<String, Object> updateAuth(Auth auth) throws Exception{
		auth.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.authMapper.updateAuth(auth);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
